import { MockMethod } from 'vite-plugin-mock';
import Mock from 'mockjs';
import playList from '../json/playList.json';
import Information from '../json/Information.json';

export default [
  {
    url: '/dev-api/article/scrollList',
    method: 'post',
    response: (options: any) => {
      const form = options.body;

      const res = [];
      for (let index = 0; index < form.size; index++) {
        const list = Mock.mock({
          'id|+1': '@increment',
          data: "@date('yyyy-MM-dd')",
          ip: '@ip',
          url: "@url('http')",
        });
        res.push(list);
      }
      return {
        code: 200,
        data: res,
        msg: '操作成功',
      };
    },
  },
  {
    url: '/dev-api/playList',
    method: 'get',
    response: () => {
      const list = playList.list;
      const data = list.map((J) => {
        return {
          title: J.name,
          artist: J.ar[0].name,
          picUrl: J.al.picUrl,
          id: J.id,
        };
      });

      return {
        code: 200,
        data,
        msg: '操作成功',
      };
    },
  },
  {
    url: '/dev-api/information',
    method: 'get',
    response: () => {
      return {
        code: 200,
        data: Information.data,
        msg: '操作成功',
      };
    },
  },
] as MockMethod[]; // 这里其实就是定义数据格式的，不了解的同学可以参考typescript的官方文档
